package com.gsn.common;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.ParticleEffect;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.ClickListener;
import com.badlogic.gdx.scenes.scene2d.ui.FlickScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.GsnImageButton;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.gsn.desktop.engine.ActorUtility;
import com.gsn.engine.gdx.GsnParticleActor;
import com.gsn.engine.myplay.GsnLayer;
import com.gsn.poker.asset.FontTexture;
import com.gsn.poker.asset.PokerSound;
import com.gsn.poker.asset.PortalTexture;
import com.gsn.poker.game.MyPoker;

public class ShopGoldLayer extends GsnLayer {
	private static final String tag = "DialogLayer";
	float time = 0.5f;
	protected ParticleEffect clickEff;
	public int id;
	Label labelGold;
	Label labelXu;
	GsnImageButton agree;
	GsnImageButton cancel;
	public boolean init = false;

	public ShopGoldLayer(float width, float height) {
		super(width, height);

		// scrollShopGold.y = bgQuickShop.y + bgQuickShop.height * 0.02f;
		// scrollShopGold.x = bgQuickShop.x + (bgQuickShop.width -
		// scrollShopGold.width)/2;
	}

	public void init() {
		if (init)
			return;
		PortalTexture portalTexture = PortalTexture.inst();

		Image bgDark = new Image(PortalTexture.inst().bgDarkDialog);
		PortalTexture.inst().scaleActor(bgDark);
		addActor(bgDark);
		bgDark.width = width;
		bgDark.height = height;

		Image bg = new Image(PortalTexture.inst().bgDialog);
		PortalTexture.inst().scaleActor(bg);
		addActor(bg);
		bg.x = (width - bg.width) / 2;
		bg.y = (height - bg.height) / 2;
		float pad = width * 0.01f;
		Label labelTitle = new Label("Cửa hàng", new Label.LabelStyle(FontTexture.inst().fontMedium, new Color(1, 1, 1, 1)));
		addActor(labelTitle);
		labelTitle.x = bg.x + bg.width * 0.05f;
		labelTitle.y = bg.y + bg.height * 0.92f;

		ShopGold shopGold = new ShopGold(this);
		shopGold.init();
		// addActor(shopGold);
		// Image bg1 = new Image(PortalTexture.inst().bgDialog);
		// PortalTexture.inst().scaleActor(bg1);

		FlickScrollPane scrollShopGold = new FlickScrollPane(shopGold);

		// scrollShopGold.setupOverscroll(30, 50, 100);
		// scrollShopGold.width = 100;
		// scrollShopGold.height = 100;
		addActor(scrollShopGold);
		Image image = new Image(portalTexture.changeGoldButton);
		portalTexture.scaleActor(image);
		scrollShopGold.width = shopGold.width;
		scrollShopGold.height = bg.height * 0.75f;
		scrollShopGold.x = bg.x + (bg.width - scrollShopGold.width) / 2;
		scrollShopGold.y = bg.y + bg.height * 0.1f;

		GsnImageButton close = new GsnImageButton(PortalTexture.inst().closeButton, PortalTexture.inst().closeButtonPress);
		PortalTexture.inst().scaleActor(close);
		addActor(close);
		close.x = bg.x + bg.width - close.getRealWidth() * 1.4f;
		close.y = bg.y + bg.height - close.getRealHeight() * 1.1f;
		close.setClickListener(new ClickListener() {

			@Override
			public void click(Actor actor, float x, float y) {
				// TODO Auto-generated method stub
				PokerSound.playClick();
				hide();
			}
		});
		// scrollShopGold.setWidget(shopGold);
	}

	public InputProcessor oldInput;

	public void show() {
		init();
		oldInput = Gdx.input.getInputProcessor();

		visible = true;
		setInputListener();
	}

	public void hide() {
		Gdx.input.setInputProcessor(oldInput);
		oldInput = null;
		visible = false;
	}

	public void showParticle(Actor actor, float x, float y) {
		GsnParticleActor par = new GsnParticleActor(PortalTexture.inst().clickEff);
		Vector2 v = ActorUtility.getCoordinate(actor, x, y, this.root);

		par.setPostition(v.x, v.y);

		par.act(100000);
		addActor(par);
		par.start();
	}

	@Override
	public boolean keyDown(int keycode) {
		switch (keycode) {
		case Keys.A:
			System.out.println("----------------");
			for (GsnLayer l : MyPoker.game.chooseChannelScreen.layers) {
				System.out.println(l.getClass().getName());
			}
			break;
		}
		return super.keyDown(keycode);
	}

}
